<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>JS Cloud Web-Server</title>

<script type="text/javascript" src="json2.js"></script>
<script type="text/javascript" src="/static/jquery-1.2.6.min.js"></script>

<script type="text/javascript" src="gears_init.js"></script>
<script type="text/javascript">
// main.js

$(document).ready(function () {

    if(!( window.google && google.gears )) {
		$("#gears").show()
		return
    }

    var wp = google.gears.factory.create('beta.workerpool');

    wp.onmessage = function(a, b, message) {
        if(message.body.action == "log") {
        	if(window.console) {
    			console.log(message.body.message)
        	}
        	$('#log').append(message.body.message+"<br>\n")
        }
    };
    
    $('#start').click(function () {
        var childWorkerId = wp.createWorkerFromUrl('thread.merged.js');
        $('#threads').append('<option value="'+childWorkerId+'">Thread '+childWorkerId+'</option>')
        wp.sendMessage({action: "start", config: { id: childWorkerId }}, childWorkerId)
    }).click()

    $('#stopThread').click(function () {
        var option = $('#threads option:selected')
        var childWorkerId = option.val();
        option.remove()
  		
  		if(childWorkerId) {
        	wp.sendMessage({action: "stop"}, parseInt(childWorkerId, 10))
  		}
    })

    $('#stop').click(function () {
        var option = $('#threads option').each(function () {
			var option = $(this)
        	var childWorkerId = option.val();
    	    option.remove()
  		
  			if(childWorkerId) {
    	    	wp.sendMessage({action: "stop"}, parseInt(childWorkerId, 10))
  			}
        })
    })
})

</script>

</head>

<body>

<form>
<h1>JS Cloud Web-Server</h1>
<p style="display: none" id=gears>This application requires <a href="http://gears.google.com/">Google Gears</a>. 
Please install it. You can, howver, use the <a href="client.html" target="_blank">test client</a> without Gears.</p>

<input type="button" value="Start Thread" id=start>
<select id="threads" size=4>
</select>
<input type="button" value="Stop Thread" id=stopThread>
<input type="button" value="Stop Server" id=stop>

<p><a href="client.html" target="_blank">Test Request</a></p>

<h2>Log</h2>
<div id=log style="height: 300px; overflow:auto;"></div>
</form>

</body>
</html>
